package io.github.aaron.commonadmin.base.beanmap;

import org.apache.commons.collections4.CollectionUtils;
import java.util.ArrayList;
import java.util.List;

public class BeanMapper {

    /**
     * 转为目标对象
     * @param beanMapping
     * @param <T>
     * @return
     */
    public static  <T> T map(BeanMapping<T> beanMapping){
        if (beanMapping == null){
            return null;
        }
        return beanMapping.map();
    }

    /**
     * 转为目标对象集合
     * @param beanMappingList
     * @param <T>
     * @return
     */
    public static <T> List<T> mapAsList(List<? extends BeanMapping<T>> beanMappingList){
        if (CollectionUtils.isEmpty(beanMappingList)){
            return new ArrayList<>();
        }
        List<T> mapList = new ArrayList<>(beanMappingList.size());
        for (BeanMapping<T> beanMapping : beanMappingList) {
            mapList.add(map(beanMapping));
        }
        return mapList;
    }

}
